<?php
namespace Fwadmin\Controller;
use Think\Controller;

class UploadsController extends Controller{
	public function index(){
		$this -> display();
	}
	public function upload(){
		$type = I('get.type');
		$this -> ajaxReturn(uploadify($type));
	}
//添加Uploadify图册图片
	public function photoAdd(){
		$Data = D('Gallery');
		if($Data -> create()){
			if($Data -> add($data) !== false){
				$data = array(
					'status'	=> 1,
					'info'		=> '图片添加成功',
				);
			} else {
				$data = array(
					'status'	=> 0,
					'info'		=> '图片添加失败',
				);
			} 
		}
		$this -> ajaxReturn($data);	
	}
//修改Uploadify图片名称
	public function changeName(){
		if(IS_AJAX){
			$Data				= D('Gallery');
			$info['name']		= I('post.title');
			$info['image_src']	= I('post.image_src');
			if($Data -> create()){
				if($Data -> where(array('image_src' => $info['image_src'])) -> setField('name',$info['name']) !== false){
					$data = array(
						'status'	=> 1,
						'info'		=> '修改成功',
					);
				} else {
					$data = array(
						'status'	=> 0,
						'info'		=> '修改失败',
					);
				} 
			}
			$this -> ajaxReturn($data);
		}else{
			exit('需要AJAX提交信息');
		}
	}
//修改Uploadify图片描述
	public function changeDesc(){
		if(IS_AJAX){
			$Data				= D('Gallery');
			$info['desc']		= I('post.desc');
			$info['image_src']	= I('post.image_src');
			if($Data -> create()){
				if($Data -> where(array('image_src' => $info['image_src'])) -> setField('desc',$info['desc']) !== false){
					$data = array(
						'status'	=> 1,
						'info'		=> '修改成功',
					);
				} else {
					$data = array(
						'status'	=> 0,
						'info'		=> '修改失败',
					);
				} 
			}
			$this -> ajaxReturn($data);
		}else{
			exit('需要AJAX提交信息');
		}
	}
//修改Uploadify图片排序
	public function changeSort(){
		if(IS_AJAX){
			$Data				= D('Gallery');
			$info['order_id']	= I('post.order_id');
			$info['image_src']	= I('post.image_src');
			if($Data -> create()){
				if($Data -> where(array('image_src' => $info['image_src'])) -> setField('order_id',$info['order_id']) !== false){
					$data = array(
						'status'	=> 1,
						'info'		=> '修改成功',
					);
				} else {
					$data = array(
						'status'	=> 0,
						'info'		=> '修改失败',
					);
				} 
			}
			$this -> ajaxReturn($data);
		}else{
			exit('需要AJAX提交信息');
		}
	}
//删除Uploadify类图片
	public function photoDel(){
		$thumb = __ROOT__.'.'.trim(I('thumb'));
		if(file_exists($thumb)){
			@unlink($thumb);
		}else{
			echo "图片不存在";	
		}
	}
//删除Uploadify类图册
	public function galleryDel(){
		$img_url	= I('post.image_src');             
		$tb_img_url	= get_tb_img_url($img_url);
		@unlink('.'.$tb_img_url);
		$result		= D('Gallery') -> where(array('image_src' => $img_url)) -> delete();
		if(@unlink('.'.$img_url) && $result !== false){
			$data = array(
				'status'	=> 1,
				'info'		=> '删除成功',
			);
		}else{
			$data = array(
				'status'	=> 0,
				'info'		=> '删除失败',
			);
		}
		$this -> ajaxReturn($data);
	}
}